package edu.bu.cs673.superkids123.children.controller.games;

import java.util.List;

import edu.bu.cs673.superkids123.AbstractFrame;
import edu.bu.cs673.superkids123.children.DataObjectAccess.LessonGameManager;
import edu.bu.cs673.superkids123.children.controller.AbstractGameController;
import edu.bu.cs673.superkids123.children.model.Game;
import edu.bu.cs673.superkids123.children.view.games.ArcheryGameView;
import edu.bu.cs673.superkids123.children.view.games.GameResultsView;

/**
 * The control for the archery game.
 * 
 * @author Noah Fredriks
 * 
 */
public class ArcheryGameController extends AbstractGameController {

	private static final int POINTS_PER_QUESTION = 10;
	private GameResultsController resultsController;

	public ArcheryGameController(AbstractFrame mainFrame) {
		super(mainFrame);
		resultsController = getMainFrame().getController(GameResultsController.class);
	}

	public void startGame() {
		resultsController.notifyResultsController("Archery Game");

		// Start Stat Recording
		List<Game> games = LessonGameManager.getAllActiveGames();
		for (Game game : games) {
			if (game.getName().contains("Archery"))
				start(game);
		}
		
		getMainFrame().changeView(ArcheryGameView.class);
	}

	/**
	 * Ends the game and saves the result. pass true if entire game was completed pass false if game
	 * is only partially complete, records in db at "Incomplete"
	 * 
	 * @param complete
	 */
	public void endGame(boolean complete) {
		if (isActive()) {
			int score = resultsController.getCorrect() * POINTS_PER_QUESTION;
			stop(complete, score);
		}

		if (complete) {
       		getMainFrame().getController(GameResultsController.class)
       			.showResultsScreen(this.getEarnedAchievements());
		}
	}
}
